<?php require("../templates/comun.php"); 
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if ($_GET['error']==1)
{ $texterror="<font color='red'>Acceso denegado</font><br> No le est&aacute; permitido el acceso a esta zona. ";}
else{ $texterror=" ";}

if (isset($_POST['usuarios'])) {
  $loginUsername=$_POST['usuarios'];
  //$password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "list_codigossugeridos.php";
  $MM_redirectLoginFailed = "index.php?error=1";
  $MM_redirecttoReferrer = false;
  //mysql_select_db($database_cnx_pizzeta, $cnx_pizzeta);
  
  $LoginRS__query=sprintf("SELECT clave_cte FROM accesos_clientes WHERE clave_cte='%s' AND tipo_usuario='A'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
/*****/
   $conexion=Obtener_Conexion();
   $LoginRS=pg_query($conexion,$LoginRS__query)  or die ("Error linea: 52 -  $LoginRS__query");
	
	$creado = pg_affected_rows($res);
	Desconectar($conexion);
	  echo $creado."|".$insertSQL;
/****/

 // $LoginRS = mysql_query($LoginRS__query, $cnx_pizzeta) or die(mysql_error());
  $row_rs_login = pg_fetch_assoc($LoginRS);
  $loginFoundUser = pg_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      
	$_SESSION['Administrador']=$row_rs_login['Administrador'];

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Morsa Consulta Codigos Sugeridos</title>
</head>

<body><form action="<?php echo $loginFormAction; ?>" method="POST" name="login">
  <div align="center"><br />
    <br />
    <br />
    <br />
    <strong>Acceso</strong> </div>
  <table width="200" border="0" align="center" bgcolor="#EBEBEB">
   <tr>
    <td  colspan="2" align="center"><?php echo $texterror; ?></td>
</td>
  <tr>
    <td align="right">Usuario:</td>
    <td><input name="usuarios" type="password" size="20" maxlength="20" />
</td>
    
  </tr>
 <!--  <tr>
  
    <td align="right">Password:</td>
    <td><input name="password" type="password" size="20" maxlength="20" /></td>
  </tr> -->
  <tr>
   
    <td  align="center" colspan="2"><input name="Accesar" type="submit" value="Entrar" /></td>
  </tr>
</table>

</form>
</body>
</html>
